//
//  ZYCTeachingPlanCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/31.
//

#import "ZYCTeachingPlanCell.h"
#import "ZYCNewBulletinModel.h"

@interface ZYCTeachingPlanCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) UIImageView *annexImageView;
@property (nonatomic, strong) UILabel *annexLabel;
@property (nonatomic, strong) UIButton *downloadButton;
@end
@implementation ZYCTeachingPlanCell

- (void)setModel:(ZYCNoticeFileModel *)model{
    _model = model;
    _annexLabel.text = model.fileName;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.line];
        [self.contentView addSubview:self.annexImageView];
        [self.contentView addSubview:self.annexLabel];
        [self.contentView addSubview:self.downloadButton];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15.0f);
            make.top.equalTo(self.contentView).offset(20.0f);
        }];
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(10.0f);
            make.right.equalTo(self.contentView).offset(-10.0f);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(17.0f);
            make.height.mas_equalTo(1.0f);
        }];
        [self.annexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15.0f);
            make.top.equalTo(self.line.mas_bottom).offset(15.0f);
            make.size.mas_equalTo(CGSizeMake(35.0f, 40.0f));
        }];
        [self.annexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.annexImageView.mas_right).offset(6.5f);
            make.centerY.equalTo(self.annexImageView);
        }];
        [self.downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.annexLabel.mas_right).offset(21.0f);
            make.centerY.equalTo(self.annexImageView);
        }];

    }
    return self;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kSystemBoldFont(17.0f) titleColor:HEX_RGB(@"#262A28") textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}


- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#EAEAEA");
    }
    return _line;
}


- (UIImageView *)annexImageView {
    if (!_annexImageView) {
        _annexImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fujian"]];
    }
    return _annexImageView;
}

- (UILabel *)annexLabel {
    if (!_annexLabel) {
        _annexLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 15.0f) titleColor:HEX_RGB(@"#262A28") textAlignment:ZZTextAlignmentLeft];
    }
    return _annexLabel;
}

- (UIButton *)downloadButton {
    if (!_downloadButton) {
        _downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _downloadButton.titleLabel.font =  kCustomFont(@"#2079D3", 15.0f);
        NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
        NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:@"下载" attributes:attribtDic];
        _downloadButton.titleLabel.attributedText = attribtStr;
        [_downloadButton addTarget:self action:@selector(clickDownloadAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _downloadButton;
}

- (void)clickDownloadAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(teachingPlanCellDidDownload:)]) {
        [self.delegate teachingPlanCellDidDownload:self.model];
    }
}

@end
